package com.jdbc.studyJDBC;

public class TestExtends {
    public static void main(String[] args) {
        Benz benz = new Benz();
        Car car = new Car();
        //对benz继承Car的属性进行赋值
        benz.setLenght(200);
        benz.setName("Benz");
        //分别输出benz、car的属性 benz对属性赋值并不影响car的属性
        System.out.println(benz.getLenght());
        System.out.println(benz.getName());
        System.out.println(car.getLenght());
        System.out.println(car.getName());
        System.out.println(benz.describe);
        benz.method();
    }
}
class Car{
    private int weight;
    private int lenght;
    private String name;

    public Car(){
        System.out.println("这是Benz的父类");
    }
    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    public int getLenght() {
        return lenght;
    }

    public void setLenght(int lenght) {
        this.lenght = lenght;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
class Benz extends Car{
    String describe = "这是Benz类自己的属性";
    public Benz(){
        System.out.println("Benz的构造器");
    }
    public void method(){
        System.out.println("这是Benz类自己的方法");
    }
}
